package com.travel.bootmall.controller;

import com.travel.bootmall.bean.User;
import com.travel.bootmall.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/web")
public class WebController {

    @Autowired
    UserService userService;

    @RequestMapping
    public String web(ModelMap map){
        map.put("title","FIRST BLOOD");
        return "spotout";
    }

    @RequestMapping("/look")
    public String product(ModelMap map){
        List<User> products = userService.tickAll();
        map.put("products",products);
        return "product1";
    }

    @RequestMapping("/json")
    public List<User> product12(){
        List<User> products = userService.tickAll();
        return products;
    }
    @RequestMapping("/product")
    public String product1(){
        return "product";
    }

    @PostMapping("/product")
    public String addAndGetProducts(@RequestBody User user){
        User newProduct = new User();
        userService.renewProduct(newProduct);
        return "product";
    }



}
